package com.sws.worktive.util;

import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.sws.worktive.R;

public class JobDialog extends DialogFragment {

	public static JobDialog newInstance(String isImage, String jobDescription) {
		JobDialog jobDialog = new JobDialog();

		Bundle arg = new Bundle();
		arg.putString("jobDescrition", jobDescription);
		arg.putString("isImage", isImage);
		jobDialog.setArguments(arg);
		return jobDialog;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.job_dialog, container, false);

		if (getArguments().getString("isImage").equals("0")) {
			
			TextView txtJobDescription = (TextView) view
					.findViewById(R.id.txt_jobDescription);
            txtJobDescription.setVisibility(View.VISIBLE);
			txtJobDescription
					.setText(getArguments().getString("jobDescrition"));
		} else if (getArguments().getString("isImage").equals("1")) {
			ImageView imageView = (ImageView) view
					.findViewById(R.id.img_jobDescription);
			imageView.setVisibility(View.VISIBLE);
			String urlString = getArguments().getString("jobDescrition");
			Picasso.with(getActivity()).load(urlString).into(imageView);
		}

		view.findViewById(R.id.btnCross).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						getDialog().dismiss();
					}
				});

		return view;
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		// TODO Auto-generated method stub

		Dialog dialog = super.onCreateDialog(savedInstanceState);

		// request a window without the title
		dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
		return dialog;
	}

}
